package cn.itcast.springbook.config;

import cn.itcast.springbook.interceptor.LoginInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 21195
 * @version v1.0
 * @package cn.itcast.springbook.config
 * @description:
 * @date 2019/6/13 16:43
 **/

/**
 * 定义配置类  注册拦截器
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    /**
     * 通过@Bean注解将我们定义的拦截器注册到spring容器
     */
    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }
    /**
     * 重写接口中的addInterceptors方法，添加自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        //通过registry来注册拦截器，通过addPathPatterns来添加路径
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/*");
    }


}
